import { useHttp } from "./http";
import { User } from "../types/user";
import { useQuery } from "react-query";

export const useUsers = (param?: Partial<User>) => {
  const client = useHttp();
  //param 变化的时候会触发
  return useQuery<User[]>(["users", param], () =>
    client("users", { data: param })
  );
};
// export const useUsers = (param?: Partial<User>) => {
//     const client = useHttp();
//     const {run, ...result} = useAsync<User[]>();
//
//     useMount(() => {
//         run(client("users", {data: clearObject(param || {})}));
//     });
//
//     return result;
// };
